package br.com.edoc.fabrica;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import br.com.edoc.gerentes.GerenteCadastro;
import br.com.edoc.gerentes.GerenteCadastroImpl;
import br.com.edoc.gerentes.GerenteControleAcesso;
import br.com.edoc.gerentes.GerenteControleAcessoImpl;
import br.com.edoc.gerentes.GerenteUploadIcones;
import br.com.edoc.gerentes.GerenteUploadIconesImpl;

@Configuration
public class FabricaGerentes implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7601506845283091457L;
	
	private List<Advisor> lista;
	
	public @Bean GerenteUploadIcones gerenteUploadIcones(){
		GerenteUploadIcones gu= new GerenteUploadIconesImpl();	
		return gu;
	}


	public @Bean GerenteControleAcesso gerenteControleAcesso(){
		GerenteControleAcesso gc= new GerenteControleAcessoImpl();		
		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.setTarget(gc);
		proxyFactory.addAdvisors(getLista());
		return (GerenteControleAcesso) proxyFactory.getProxy();
	}
	public @Bean GerenteCadastro gerenteCadastro(){
		GerenteCadastro gc= new GerenteCadastroImpl();		
		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.setTarget(gc);
		proxyFactory.addAdvisors(getLista());
		return (GerenteCadastro) proxyFactory.getProxy();
	}

	
	public List<Advisor> getLista() {
		if(lista==null){
			FabricaInterceptPoint fabrica = new FabricaInterceptPoint();
			lista = new ArrayList<Advisor>();
			lista.addAll(fabrica.getInterceptPointConsulta());
			lista.addAll(fabrica.getInterceptPointSaveOrUpdate());
		}
		return lista;
	}
	
	public void setLista(List<Advisor> lista) {
		this.lista = lista;
	}
	
}